from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-15 14:02:24.403372
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 15, Jun, 2022
Time: 14:02:31
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5172
Nobs: 688.000 HQIC: -49.8809
Log likelihood: 8541.88 FPE: 1.72731e-22
AIC: -50.1103 Det(Omega_mle): 1.51694e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.302895 0.058846 5.147 0.000
L1.Burgenland 0.105936 0.038240 2.770 0.006
L1.Kärnten -0.109606 0.020208 -5.424 0.000
L1.Niederösterreich 0.201789 0.080028 2.521 0.012
L1.Oberösterreich 0.107493 0.078355 1.372 0.170
L1.Salzburg 0.257181 0.040889 6.290 0.000
L1.Steiermark 0.047871 0.053502 0.895 0.371
L1.Tirol 0.109125 0.043209 2.525 0.012
L1.Vorarlberg -0.054679 0.037620 -1.453 0.146
L1.Wien 0.036983 0.069576 0.532 0.595
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048052 0.123890 0.388 0.698
L1.Burgenland -0.035828 0.080508 -0.445 0.656
L1.Kärnten 0.040781 0.042545 0.959 0.338
L1.Niederösterreich -0.180280 0.168483 -1.070 0.285
L1.Oberösterreich 0.436226 0.164962 2.644 0.008
L1.Salzburg 0.285279 0.086083 3.314 0.001
L1.Steiermark 0.107606 0.112638 0.955 0.339
L1.Tirol 0.315101 0.090969 3.464 0.001
L1.Vorarlberg 0.024696 0.079201 0.312 0.755
L1.Wien -0.034284 0.146479 -0.234 0.815
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188047 0.030131 6.241 0.000
L1.Burgenland 0.089182 0.019580 4.555 0.000
L1.Kärnten -0.007730 0.010347 -0.747 0.455
L1.Niederösterreich 0.258802 0.040976 6.316 0.000
L1.Oberösterreich 0.138896 0.040120 3.462 0.001
L1.Salzburg 0.045620 0.020936 2.179 0.029
L1.Steiermark 0.024390 0.027394 0.890 0.373
L1.Tirol 0.090125 0.022124 4.074 0.000
L1.Vorarlberg 0.058231 0.019262 3.023 0.003
L1.Wien 0.115583 0.035625 3.244 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109286 0.030494 3.584 0.000
L1.Burgenland 0.044301 0.019816 2.236 0.025
L1.Kärnten -0.013965 0.010472 -1.334 0.182
L1.Niederösterreich 0.186386 0.041471 4.494 0.000
L1.Oberösterreich 0.306474 0.040604 7.548 0.000
L1.Salzburg 0.104781 0.021189 4.945 0.000
L1.Steiermark 0.109395 0.027725 3.946 0.000
L1.Tirol 0.102449 0.022391 4.575 0.000
L1.Vorarlberg 0.070233 0.019495 3.603 0.000
L1.Wien -0.020190 0.036054 -0.560 0.575
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128452 0.056086 2.290 0.022
L1.Burgenland -0.050991 0.036447 -1.399 0.162
L1.Kärnten -0.045026 0.019260 -2.338 0.019
L1.Niederösterreich 0.148868 0.076274 1.952 0.051
L1.Oberösterreich 0.148821 0.074680 1.993 0.046
L1.Salzburg 0.282057 0.038971 7.238 0.000
L1.Steiermark 0.054458 0.050992 1.068 0.286
L1.Tirol 0.165742 0.041182 4.025 0.000
L1.Vorarlberg 0.092589 0.035855 2.582 0.010
L1.Wien 0.077503 0.066312 1.169 0.243
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059268 0.044235 1.340 0.180
L1.Burgenland 0.033075 0.028745 1.151 0.250
L1.Kärnten 0.051081 0.015191 3.363 0.001
L1.Niederösterreich 0.207314 0.060157 3.446 0.001
L1.Oberösterreich 0.297782 0.058900 5.056 0.000
L1.Salzburg 0.044108 0.030736 1.435 0.151
L1.Steiermark 0.008971 0.040217 0.223 0.823
L1.Tirol 0.138167 0.032480 4.254 0.000
L1.Vorarlberg 0.075893 0.028279 2.684 0.007
L1.Wien 0.085000 0.052300 1.625 0.104
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173473 0.053195 3.261 0.001
L1.Burgenland -0.002587 0.034568 -0.075 0.940
L1.Kärnten -0.063454 0.018268 -3.474 0.001
L1.Niederösterreich -0.088046 0.072343 -1.217 0.224
L1.Oberösterreich 0.197427 0.070831 2.787 0.005
L1.Salzburg 0.055211 0.036962 1.494 0.135
L1.Steiermark 0.243113 0.048364 5.027 0.000
L1.Tirol 0.497521 0.039060 12.737 0.000
L1.Vorarlberg 0.049391 0.034007 1.452 0.146
L1.Wien -0.059569 0.062895 -0.947 0.344
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162150 0.060369 2.686 0.007
L1.Burgenland -0.013640 0.039230 -0.348 0.728
L1.Kärnten 0.063580 0.020731 3.067 0.002
L1.Niederösterreich 0.196816 0.082098 2.397 0.017
L1.Oberösterreich -0.072808 0.080383 -0.906 0.365
L1.Salzburg 0.207939 0.041947 4.957 0.000
L1.Steiermark 0.138379 0.054886 2.521 0.012
L1.Tirol 0.065110 0.044327 1.469 0.142
L1.Vorarlberg 0.125087 0.038593 3.241 0.001
L1.Wien 0.129923 0.071376 1.820 0.069
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.368715 0.035048 10.520 0.000
L1.Burgenland 0.005077 0.022775 0.223 0.824
L1.Kärnten -0.023508 0.012036 -1.953 0.051
L1.Niederösterreich 0.215583 0.047663 4.523 0.000
L1.Oberösterreich 0.204844 0.046667 4.389 0.000
L1.Salzburg 0.043273 0.024353 1.777 0.076
L1.Steiermark -0.016782 0.031865 -0.527 0.598
L1.Tirol 0.105677 0.025735 4.106 0.000
L1.Vorarlberg 0.069378 0.022406 3.096 0.002
L1.Wien 0.029821 0.041438 0.720 0.472
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037064 0.130763 0.189257 0.150765 0.112206 0.094856 0.053570 0.215884
Kärnten 0.037064 1.000000 -0.017380 0.132722 0.054529 0.092035 0.437958 -0.054847 0.092466
Niederösterreich 0.130763 -0.017380 1.000000 0.333822 0.138846 0.292245 0.084563 0.171632 0.311074
Oberösterreich 0.189257 0.132722 0.333822 1.000000 0.223023 0.318295 0.169451 0.153487 0.262852
Salzburg 0.150765 0.054529 0.138846 0.223023 1.000000 0.135712 0.112739 0.137640 0.129437
Steiermark 0.112206 0.092035 0.292245 0.318295 0.135712 1.000000 0.142773 0.121602 0.068406
Tirol 0.094856 0.437958 0.084563 0.169451 0.112739 0.142773 1.000000 0.105313 0.141028
Vorarlberg 0.053570 -0.054847 0.171632 0.153487 0.137640 0.121602 0.105313 1.000000 0.003023
Wien 0.215884 0.092466 0.311074 0.262852 0.129437 0.068406 0.141028 0.003023 1.000000